package com.yesjpt.web;

import com.yesjpt.domain.User;
import com.yesjpt.serv.UserServ;
import com.yesjpt.util.L;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user") // 上下文路径
public class UserController {
	@Autowired private UserServ serv;
	
	
	@GetMapping("/{id}")
    public User getUser(@PathVariable String id) {
    	L.begin(new Throwable().getStackTrace()[0] + ", id = " + id);
    	User vo = serv.findById(id);
    	L.end(new Throwable().getStackTrace()[0]);
    	return vo;
    }
	
	// 不能在web层写业务逻辑
	@GetMapping("/findById")
    public User findById(String id) {
    	L.begin(new Throwable().getStackTrace()[0] + ", id = " + id);
    	User vo = new User(id, "用户_" + id);
    	return vo;
    }
	
	@GetMapping("/listAll")
    public Object listAll() {
		L.begin(new Throwable().getStackTrace()[0]);
		List<User> all = serv.listAll();
		L.end(new Throwable().getStackTrace()[0]);
    	return all;
    }
}
